package edu.njust.cma.controller;

import edu.njust.cma.pojo.Equipment;
import edu.njust.cma.pojo.Result;
import edu.njust.cma.service.EquipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/equipment")
public class EquipController {
    @Autowired
    private EquipService equipService;

    //1.查询设备列表
    @GetMapping("/list")
    public Result equipList() {
        List<Equipment> equipList = equipService.equipList();
        return Result.success(equipList);
    }

    //2.添加设备
    @PostMapping("/addEquip")
    public Result addEquip(@RequestBody Equipment equipment) {
        equipService.addEquip(equipment);
        return Result.success();
    }

    //3.删除设备
    @DeleteMapping("/deleteEquip/{id}")
    public Result deleteEquip(@PathVariable int id) {
        equipService.deleteEquip(id);
        return Result.success();
    }

    //4.修改设备信息
    @PutMapping("/updateEquip")
    public Result updateEquip(@RequestBody Equipment equipment) {
        equipService.updateEquip(equipment);
        return Result.success();
    }

    //5.通过关键字查询设备
    @GetMapping("/searchEquip/{keyword}")
    public Result searchEquip(@PathVariable String keyword) {
        List<Equipment> equipList = equipService.searchEquip(keyword);
        return Result.success(equipList);
    }
}
